package com.esri.android.map.ags;

import android.util.Log;
import com.esri.android.map.DynamicLayer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.MapGeometry;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.tasks.ags.k;
import com.esri.core.internal.tasks.ags.l;
import com.esri.core.internal.tasks.ags.s;
import com.esri.core.internal.value.a;
import com.esri.core.io.EsriSecurityException;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.ImageServiceParameters;
import com.esri.core.map.MosaicRule;
import com.esri.core.map.RasterFunction;
import com.esri.core.map.TimeAwareLayer;
import com.esri.core.map.TimeExtent;
import com.esri.core.map.TimeInfo;
import com.github.mikephil.charting.utils.Utils;
import java.util.concurrent.RejectedExecutionException;

/* loaded from: classes.dex */
public class ArcGISImageServiceLayer extends DynamicLayer implements TimeAwareLayer {
    private a s;
    private final ImageServiceParameters t;
    private String u;
    private String v;
    private TimeExtent w;

    public ArcGISImageServiceLayer(String str, ImageServiceParameters imageServiceParameters) {
        this(str, imageServiceParameters, null, true);
    }

    public ArcGISImageServiceLayer(String str, ImageServiceParameters imageServiceParameters, UserCredentials userCredentials, boolean z) {
        super(str);
        this.t = new ImageServiceParameters(imageServiceParameters);
        this.credentials = userCredentials;
        if (z) {
            try {
                getServiceExecutor().submit(new Runnable() { // from class: com.esri.android.map.ags.ArcGISImageServiceLayer.1
                    @Override // java.lang.Runnable
                    public void run() {
                        ArcGISImageServiceLayer.this.initLayer();
                    }
                });
            } catch (RejectedExecutionException unused) {
            }
        }
    }

    public ArcGISImageServiceLayer(String str, ImageServiceParameters imageServiceParameters, UserCredentials userCredentials) {
        this(str, imageServiceParameters, userCredentials, true);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.esri.android.map.DynamicLayer, com.esri.android.map.Layer
    public void initLayer() {
        if (this.nativeHandle == 0) {
            this.nativeHandle = create();
        }
        if (this.nativeHandle == 0) {
            changeStatus(OnStatusChangedListener.STATUS.fromInt(-1000));
            Log.e(com.esri.core.internal.a.a, "initialize fail : " + OnStatusChangedListener.STATUS.fromInt(-1000));
            return;
        }
        try {
            a aVar = (a) loadServiceInfo(new s(getUrl(), this.credentials));
            this.s = aVar;
            if (aVar == null) {
                throw new Exception("layer initialization failed due to invalid URL or credential");
            }
            if (getName() == null || getName().length() < 1) {
                setName(this.s.d());
            }
            MapGeometry f = this.s.f();
            SpatialReference spatialReference = f != null ? f.getSpatialReference() : null;
            Envelope envelope = f != null ? (Envelope) f.getGeometry() : null;
            initializeMinMaxScale(this.s.x(), this.s.y());
            setFullExtent(envelope);
            setDefaultSpatialReference(spatialReference);
            if (getInitialExtent() == null) {
                setInitialExtent(this.s.g());
            } else {
                setInitialExtent((Envelope) GeometryEngine.project(getInitialExtent(), SpatialReference.create(4326), getDefaultSpatialReference()));
            }
            super.initLayer();
        } catch (Exception e) {
            Log.e(com.esri.core.internal.a.a, "url =" + getUrl(), e);
            if (e instanceof EsriSecurityException) {
                changeStatus(OnStatusChangedListener.STATUS.fromInt(((EsriSecurityException) e).getCode()));
            } else {
                changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_ARCGIS_DYNAMIC_LAYER));
            }
        }
    }

    @Override // com.esri.android.map.DynamicLayer
    protected byte[] getImage(int i, int i2, Envelope envelope) throws Exception {
        TimeExtent timeExtent;
        l lVar = new l();
        k kVar = new k(lVar, getUrl(), this.credentials);
        lVar.c(isWrapAroundEnabled());
        lVar.a(getCenterMeridan());
        lVar.d(isCrossDateline());
        lVar.a(envelope);
        lVar.b(getSpatialReference());
        lVar.a(i);
        lVar.b(i2);
        lVar.a(this.t);
        lVar.a(getSpatialReference());
        lVar.a(this.s);
        lVar.a(this.v);
        if (isTimeAware() && (timeExtent = this.w) != null) {
            lVar.a(timeExtent);
        }
        return kVar.execute();
    }

    public void setBandIds(int[] iArr) {
        this.t.setBandIds(iArr);
    }

    public int[] getBandIds() {
        return this.t.getBandIds();
    }

    public void setCompressionQuality(int i) {
        this.t.setCompressionQuality(i);
    }

    public int getCompressionQuality() {
        return this.t.getCompressionQuality();
    }

    public void setImageFormat(ImageServiceParameters.IMAGE_FORMAT image_format) {
        this.t.setFormat(image_format);
    }

    public ImageServiceParameters.IMAGE_FORMAT getImageFormat() {
        return this.t.getFormat();
    }

    public void setInterpolation(ImageServiceParameters.RSP rsp) {
        this.t.setInterpolation(rsp);
    }

    public ImageServiceParameters.RSP getInterpolation() {
        return this.t.getInterpolation();
    }

    public void setMosaicRule(MosaicRule mosaicRule) {
        this.t.setMosaicRule(mosaicRule);
    }

    public MosaicRule getMosaicRule() {
        return this.t.getMosaicRule();
    }

    public void setRenderingRule(RasterFunction rasterFunction) {
        this.t.setRenderingRule(rasterFunction);
    }

    public RasterFunction getRenderingRule() {
        return this.t.getRenderingRule();
    }

    public double getPixelSizeX() {
        a aVar = this.s;
        return aVar != null ? aVar.i() : Utils.DOUBLE_EPSILON;
    }

    public double getPixelSizeY() {
        a aVar = this.s;
        return aVar != null ? aVar.j() : Utils.DOUBLE_EPSILON;
    }

    public ImageServiceParameters.PIXEL_TYPE getPixelType() {
        a aVar = this.s;
        if (aVar != null) {
            return aVar.l();
        }
        return null;
    }

    public int getBandCount() {
        a aVar = this.s;
        if (aVar != null) {
            return aVar.k();
        }
        return 0;
    }

    public String getCopyrightText() {
        a aVar = this.s;
        if (aVar != null) {
            return aVar.o();
        }
        return null;
    }

    public ImageServiceParameters getOptions() {
        return this.t;
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x0031 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void setLayerDefinitionOverride(java.lang.String r4) {
        /*
            r3 = this;
            r0 = 0
            r3.v = r0
            r3.u = r4
            if (r4 == 0) goto L35
            org.codehaus.jackson.JsonParser r4 = com.esri.core.internal.util.d.c(r4)     // Catch: java.lang.Throwable -> L1f java.lang.Exception -> L24
            com.esri.core.ags.LayerServiceInfo r1 = com.esri.core.ags.LayerServiceInfo.fromJson(r4)     // Catch: java.lang.Exception -> L1d java.lang.Throwable -> L2e
            if (r1 == 0) goto L15
            java.lang.String r0 = r1.getDefinitionExpression()     // Catch: java.lang.Exception -> L1d java.lang.Throwable -> L2e
        L15:
            r3.v = r0     // Catch: java.lang.Exception -> L1d java.lang.Throwable -> L2e
            if (r4 == 0) goto L35
            r4.close()     // Catch: java.io.IOException -> L35
            goto L35
        L1d:
            r0 = move-exception
            goto L28
        L1f:
            r4 = move-exception
            r2 = r0
            r0 = r4
            r4 = r2
            goto L2f
        L24:
            r4 = move-exception
            r2 = r0
            r0 = r4
            r4 = r2
        L28:
            java.lang.RuntimeException r1 = new java.lang.RuntimeException     // Catch: java.lang.Throwable -> L2e
            r1.<init>(r0)     // Catch: java.lang.Throwable -> L2e
            throw r1     // Catch: java.lang.Throwable -> L2e
        L2e:
            r0 = move-exception
        L2f:
            if (r4 == 0) goto L34
            r4.close()     // Catch: java.io.IOException -> L34
        L34:
            throw r0
        L35:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.ags.ArcGISImageServiceLayer.setLayerDefinitionOverride(java.lang.String):void");
    }

    public String getLayerDefinitionOverride() {
        return this.u;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public boolean isTimeAware() {
        a aVar = this.s;
        return (aVar == null || aVar.z() == null) ? false : true;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeExtent getTimeExtent() {
        if (isTimeAware()) {
            return this.s.z().getTimeExtent();
        }
        return null;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeExtent getTimeInterval() {
        return this.w;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public void setTimeInterval(TimeExtent timeExtent) {
        this.w = timeExtent;
        refresh();
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeInfo getTimeInfo() {
        a aVar = this.s;
        if (aVar != null) {
            return aVar.z();
        }
        return null;
    }
}
